package com.course.domain.service.impl;

import com.course.domain.dao.*;
import com.course.domain.model.*;
import com.course.domain.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Justin on 2017/5/12.
 */
@Service
public class TaskServiceImpl implements TaskService {

    private final TaskAudioDao taskAudioDao;
    private final TaskVideoDao taskVideoDao;
    private final TaskStoryDao taskStoryDao;
    private final TaskLearnDao taskLearnDao;
    private final TaskClassDao taskClassDao;
    private final TaskEventDao taskEventDao;
    private final TaskGroupDao taskGroupDao;

    @Autowired
    public TaskServiceImpl(TaskAudioDao taskAudioDao,
                           TaskVideoDao taskVideoDao,
                           TaskStoryDao taskStoryDao,
                           TaskLearnDao taskLearnDao,
                           TaskClassDao taskClassDao,
                           TaskEventDao taskEventDao,
                           TaskGroupDao taskGroupDao) {
        this.taskAudioDao = taskAudioDao;
        this.taskVideoDao = taskVideoDao;
        this.taskStoryDao = taskStoryDao;
        this.taskLearnDao = taskLearnDao;
        this.taskClassDao = taskClassDao;
        this.taskEventDao = taskEventDao;
        this.taskGroupDao = taskGroupDao;
    }

    @Override
    public TaskAudio createAudio(TaskAudio taskAudio) {
        return taskAudioDao.save(taskAudio);
    }

    @Override
    public TaskAudio updateAudio(TaskAudio taskAudio) {
        return taskAudioDao.save(taskAudio);
    }

    @Override
    public TaskVideo createVideo(TaskVideo taskVideo) {
        return taskVideoDao.save(taskVideo);
    }

    @Override
    public TaskVideo updateVideo(TaskVideo taskVideo) {
        return taskVideoDao.save(taskVideo);
    }

    @Override
    public TaskStory createStory(TaskStory taskStory) {
        return taskStoryDao.save(taskStory);
    }

    @Override
    public TaskStory updateStory(TaskStory taskStory) {
        return taskStoryDao.save(taskStory);
    }

    @Override
    public TaskLearn createLearn(TaskLearn taskLearn) {
        return taskLearnDao.save(taskLearn);
    }

    @Override
    public TaskLearn updateLearn(TaskLearn taskLearn) {
        return taskLearnDao.save(taskLearn);
    }

    @Override
    public TaskClass createClass(TaskClass taskClass) {
        return taskClassDao.save(taskClass);
    }

    @Override
    public TaskClass updateClass(TaskClass taskClass) {
        return taskClassDao.save(taskClass);
    }

    @Override
    public TaskEvent createEvent(TaskEvent taskEvent) {
        return taskEventDao.save(taskEvent);
    }

    @Override
    public TaskEvent updateEvent(TaskEvent taskEvent) {
        return taskEventDao.save(taskEvent);
    }

    @Override
    public TaskGroup createGroup(TaskGroup taskGroup) {
        return taskGroupDao.save(taskGroup);
    }

    @Override
    public TaskGroup updateGroup(TaskGroup taskGroup) {
        return taskGroupDao.save(taskGroup);
    }

    @Override
    public TaskLearn loadLearn(int learnId) {
        return taskLearnDao.findOne(learnId);
    }

    @Override
    public TaskClass loadClass(int classId) {
        return taskClassDao.findOne(classId);
    }

    @Override
    public TaskEvent loadEvent(int eventId) {
        return taskEventDao.findOne(eventId);
    }

    @Override
    public List<TaskAudio> findAudio(int courseId) {
        return taskAudioDao.findByCourseId(courseId);
    }

    @Override
    public List<TaskVideo> findVideo(int courseId) {
        return taskVideoDao.findByCourseId(courseId);
    }

    @Override
    public List<TaskStory> findStory(int courseId) {
        return taskStoryDao.findByCourseId(courseId);
    }

    @Override
    public List<TaskLearn> findLearn(int courseId) {
        return taskLearnDao.findByCourseId(courseId);
    }

    @Override
    public List<TaskClass> findClass(int courseId) {
        return taskClassDao.findByCourseId(courseId);
    }

    @Override
    public List<TaskEvent> findEvent(int courseId) {
        return taskEventDao.findByCourseId(courseId);
    }

    @Override
    public List<TaskGroup> findGroup(int courseId) {
        return taskGroupDao.findByCourseIdOrderByIdx(courseId);
    }

    @Override
    public List<TaskClass> findClass(List<Integer> taskIds) {
        return taskClassDao.findAll(taskIds);
    }

    @Override
    public void removeGroup(int id) {
        taskGroupDao.delete(id);
    }

    @Override
    public int countLearn(List<Integer> taskIds) {
        return taskGroupDao.countByTaskIdIn(taskIds);
    }
}
